package types

// 消息Part定义

type TextPart struct {
	Text string `json:"text" bson:"text"`
}

type FilePart struct {
	FileName string `json:"fileName" bson:"fileName"`
	FirlUri  string `json:"fileUri" bson:"fileUri"`
}

type FormValue struct {
	Key   string `json:"key" bson:"key"`
	Value string `json:"value" bson:"value"`
}

type FormPart struct {
	Values []FormValue `json:"values" bson:"values"`
	Submit bool        `json:"submit"`
}

type Part struct {
	TextPart *TextPart `json:"textPart" bson:"textPart"`
	FilePart *FilePart `json:"filePart" bson:"filePart"`
	FormPart *FormPart `json:"formPart" bson:"formPart"`
}

type ObjectKind string

const (
	MessageObjectKind              ObjectKind = "message"
	TaskStatusUpdateObjectKind     ObjectKind = "status-update"
	TaskArtifactUpdateObjectKind   ObjectKind = "artifact-update"
	TaskFormDefineUpdateObjectKind ObjectKind = "formdefine-update"
)

// 通讯载体

type ObjectKindAware interface {
	GetObjectKind() ObjectKind
}

type MessageRole string

const (
	UserMessageRole  MessageRole = "user"
	AgentMessageRole MessageRole = "agent"
)

type Message struct {
	MessageId string      `json:"messageId"`
	TimeStamp int64       `json:"timeStamp"`
	Role      MessageRole `json:"role"` //user or agent
	Parts     []Part      `json:"parts"`
	Kind      ObjectKind  `json:"kind"`
}

func (m *Message) GetObjectKind() ObjectKind {
	return MessageObjectKind
}

type Artifact struct {
	ArtifactId  string `json:"artifactId"`
	Name        string `json:"name"`
	Description string `json:"description"`
	TimeStamp   int64  `json:"timeStamp"`
	Parts       []Part `json:"parts"`
}

type FormFieldType string

const (
	DateFieldType     FormFieldType = "date"
	DateTimeFieldType FormFieldType = "datetime"
	EmailFieldType    FormFieldType = "email"
	FileUrlFieldType  FormFieldType = "fileurl"
	NumberFieldType   FormFieldType = "number"
	TextFieldType     FormFieldType = "text"
)

type FormField struct {
	Name        string        `json:"name"`
	Description string        `json:"description"`
	Key         string        `json:"key"`
	Value       string        `json:"value"`
	ValueType   FormFieldType `json:"valueType"`
	Optional    bool          `json:"optional"`
}

type FormDefine struct { //表单定义
	FormDefineId string      `json:"formDefineId"`
	FormType     string      `json:"formType"`
	Name         string      `json:"name"`
	Description  string      `json:"description"`
	TimeStamp    int64       `json:"timeStamp"`
	Fields       []FormField `json:"fields"`
}

type TaskStatusUpdateEvent struct {
	TaskId string     `json:"taskId"`
	Status TaskStatus `json:"status"`
	Final  bool       `json:"final"`
	Kind   ObjectKind `json:"kind"`
}

func (e *TaskStatusUpdateEvent) GetObjectKind() ObjectKind {
	return TaskStatusUpdateObjectKind
}

type TaskArtifactUpdateEvent struct {
	TaskId   string     `json:"taskId"`
	Artifact Artifact   `json:"artifact"`
	Kind     ObjectKind `json:"kind"`
}

func (e *TaskArtifactUpdateEvent) GetObjectKind() ObjectKind {
	return TaskArtifactUpdateObjectKind
}

type TaskFormDefineUpdateEvent struct {
	TaskId     string     `json:"taskId"`
	FormDefine FormDefine `json:"formDefine"`
	Kind       ObjectKind `json:"kind"`
}

func (e *TaskFormDefineUpdateEvent) GetObjectKind() ObjectKind {
	return TaskFormDefineUpdateObjectKind
}

//任务数据定义

type TaskState string

const (
	TaskCreateed      TaskState = "createed"
	TaskWorking       TaskState = "working"
	TaskInputRequired TaskState = "input-required"
	TaskCompleted     TaskState = "completed"
	TaskCanceled      TaskState = "canceled"
	TaskFailed        TaskState = "failed"
	TaskRejected      TaskState = "rejected"
)

type TaskStatus struct {
	State     TaskState `json:"state"`
	Message   *Message  `json:"message"`
	TimeStamp int64     `json:"timeStamp"`
}

type Task struct {
	TaskId      string       `json:"taskId"`
	OwnerId     string       `json:"ownerId"`
	Status      TaskStatus   `json:"status"`
	SkillId     string       `json:"skillId"`
	Messages    []Message    `json:"messages"`
	Artifacts   []Artifact   `json:"artifacts"`
	FormDefines []FormDefine `json:"formDefines"`
}

//定义技能
type Skill struct {
	SkillId        string   `json:"skillId"`
	Name           string   `json:"name"`
	Description    string   `json:"description"`
	FilterUserRole bool     `json:"filterUserRole"`
	UserRoles      []string `json:"userRoles"`
	Examples       []string `json:"examples"`
	Default        bool     `json:"default"`
}
